﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtBusiness.FlowOperation;
using System.Data;
using System.Configuration;

public partial class MyWindow_TaskBuild : PageBase
{
    public RequestFlowOperation flowOperation = new RequestFlowOperation();

    /// <summary>
    /// 页面加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
            psSqr.Name = "所有单位";
        }
    }

    /// <summary>
    /// 数据绑定
    /// </summary>
    public void BindData()
    {
        DataTable dtTemp = flowOperation.GetWorkFlowByUserId(UserId);
        foreach (DataRow drTemp in dtTemp.Rows)
        {
            ListItem liTemp = new ListItem(drTemp["wname"].ToString(), drTemp["wid"].ToString());
            ddlSerialType.Items.Add(liTemp);
        }

        //处理地图审核特殊用途
        if (ddlSerialType.Items.Count > 0)
        {
            string strUseType = ConfigurationManager.AppSettings["specialFlowUseType"];
            foreach (string strTemp in strUseType.Split(','))
            {
                string[] arrSerialInfo = strTemp.Split(';');
                if (ddlSerialType.SelectedItem.Text == arrSerialInfo[0])
                {
                    ddclSelect.DefaultText = arrSerialInfo[1];
                }
            }
        }
    }

    /// <summary>
    /// 业务受理
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnProcess_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(psSqr.Text))
        {
            string strWiid = string.Empty;
            string strErrorMsg = string.Empty;

            int nResult = flowOperation.BuildTask(ddlSerialType.SelectedValue, UserId, psSqr.Text, ddclSelect.Text, ref strWiid, ref strErrorMsg);
            if (nResult == 1)
            {
                if (radioArray.SelectedIndex == 0)
                {
                    Response.Redirect(string.Format("../{2}?wid={0}&WorkFlowName={1}", ddlSerialType.SelectedValue, ddlSerialType.Text, ConfigurationManager.AppSettings["dbsxUrl"]));
                }
            }
            else//创建流程失败
            {
                string strMsg = string.Format("创建流程失败：{0}",strErrorMsg);
                Common.WindowAppear.WriteAlert(this.Page,strMsg);
            }
        }
        else
        {
            string strMsg = "申请单位不能为空";
            Common.WindowAppear.WriteAlert(this.Page, strMsg);
        }
    }
}
